﻿@model Test.ViewModel.LicenceLoginViewModel

@{
    ViewBag.Title = "Login";
}

<h2>登录</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Pwd, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.PasswordFor(model => model.Pwd, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Pwd, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <a class="btn btn-default" href="javascript:;" onclick="Login()">登录</a>
            </div>
        </div>
    </div>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
<script>
    function Login() {
        var name = $("#UserName").val();
        var pwd = $("#Pwd").val();
        if (name == "") {
            alert("账号不能为空");
        } else if (pwd == "") {
            alert("密码不能为空");
        } else {
            $.post(
                "@Url.Action("UserLogin","Home")",
                { "name": name, "pwd": pwd },
                function (data) {
                    alert(data.Message);
                    if (data.State==1) {
                        location.href = "/Home/Default";
                    }
                    else {
                        location.href = "/Home/Login";
                    }
                }, "json"
            );
        }
    }
</script>